package org.me.utils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.ChatManager;
import org.jivesoftware.smack.ChatManagerListener;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.ConnectionListener;
import org.jivesoftware.smack.MessageListener;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.Roster;
import org.jivesoftware.smack.RosterEntry;
import org.jivesoftware.smack.RosterGroup;
import org.jivesoftware.smack.SASLAuthentication;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.Roster.SubscriptionMode;
import org.jivesoftware.smack.filter.MessageTypeFilter;
import org.jivesoftware.smack.filter.OrFilter;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Presence.Mode;
import org.jivesoftware.smack.packet.Presence.Type;
import org.jivesoftware.smack.provider.PrivacyProvider;
import org.jivesoftware.smack.provider.ProviderManager;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.Form;
import org.jivesoftware.smackx.GroupChatInvitation;
import org.jivesoftware.smackx.OfflineMessageManager;
import org.jivesoftware.smackx.PrivateDataManager;
import org.jivesoftware.smackx.ServiceDiscoveryManager;
import org.jivesoftware.smackx.muc.InvitationListener;
import org.jivesoftware.smackx.muc.MultiUserChat;
import org.jivesoftware.smackx.packet.ChatStateExtension;
import org.jivesoftware.smackx.packet.DelayInformation;
import org.jivesoftware.smackx.packet.DiscoverInfo;
import org.jivesoftware.smackx.packet.LastActivity;
import org.jivesoftware.smackx.packet.OfflineMessageInfo;
import org.jivesoftware.smackx.packet.OfflineMessageRequest;
import org.jivesoftware.smackx.packet.SharedGroupsInfo;
//import org.jivesoftware.smackx.provider.BytestreamsProvider;
import org.jivesoftware.smackx.provider.DataFormProvider;
import org.jivesoftware.smackx.provider.DelayInformationProvider;
import org.jivesoftware.smackx.provider.DiscoverInfoProvider;
import org.jivesoftware.smackx.provider.DiscoverItemsProvider;
//import org.jivesoftware.smackx.provider.IBBProviders;
import org.jivesoftware.smackx.provider.MUCAdminProvider;
import org.jivesoftware.smackx.provider.MUCOwnerProvider;
import org.jivesoftware.smackx.provider.MUCUserProvider;
import org.jivesoftware.smackx.provider.MessageEventProvider;
import org.jivesoftware.smackx.provider.MultipleAddressesProvider;
import org.jivesoftware.smackx.provider.RosterExchangeProvider;
import org.jivesoftware.smackx.provider.StreamInitiationProvider;
import org.jivesoftware.smackx.provider.VCardProvider;
import org.jivesoftware.smackx.provider.XHTMLExtensionProvider;
import org.jivesoftware.smackx.search.UserSearch;
import org.me.TabActivity;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.util.Log;
import android.widget.Adapter;

public class Koneksi {
	
	private String server = "10.0.2.2";
	private int port = 5222;
//	private String server = "203.130.204.224";
//	private String server = "10.14.16.88";
//	private String sn =  "ChatUI/index.php/chat/bosh_proxy";
//	private int port = 88;
	
	private ConnectionConfiguration config;
	private XMPPConnection connection;
	String userChat;
    int childPosition;
    int groupPosition;
	private String requestfrom;
//    static String status_presence;
    private static String status_message;
    private static ArrayList<String> mess = new ArrayList<String>();
    private static ArrayList<String> from = new ArrayList<String>();
    private static ArrayList<String> to = new ArrayList<String>();
    
    private PacketEventDispatcher packetEventDispatcher = new PacketEventDispatcher();
	
    private static Koneksi instance = null;

    public static Koneksi getInstance() {
      if(instance==null){
        instance = new Koneksi();
      }
      return instance;
    }
    
    public XMPPConnection getConnection() {
    	return this.connection;
    }
    
    public void init() throws XMPPException {
        System.out.println(String.format("Initializing connection to server %1$s port %2$d", server, port));
        configure(ProviderManager.getInstance());
        config = new ConnectionConfiguration(server, port);
        config.setSASLAuthenticationEnabled(true);
        connection = new XMPPConnection(config);
        connection.connect();
        System.out.println();
//        connection.addConnectionListener(new ConnectionListener() {
//			
//			@Override
//			public void reconnectionSuccessful() {
//				// TODO Auto-generated method stub
//				
//			}
//			
//			@Override
//			public void reconnectionFailed(Exception arg0) {
//				// TODO Auto-generated method stub
//				
//			}
//			
//			@Override
//			public void reconnectingIn(int arg0) {
//				// TODO Auto-generated method stub
//				
//			}
//			
//			@Override
//			public void connectionClosedOnError(Exception arg0) {
//				// TODO Auto-generated method stub
//				System.out.println("2350916     "+arg0);
//			}
//			
//			@Override
//			public void connectionClosed() {
//				// TODO Auto-generated method stub
//				System.out.println("         safhuewiauhf");
//			}
//		});
        
        System.out.println("Connected: " + connection.isConnected());
    }

    public void performLogin(String username, String password) throws XMPPException {
        if (connection!=null && connection.isConnected()) {
            connection.login(username, password);
        }
        
//        connection.addPacketListener(new PacketListener() {
//			
//			@Override
//			public void processPacket(Packet packet) {
//				System.out.println("processPacket= "+packet.toXML());
//				// TODO Auto-generated method stub
//				packetEventDispatcher.fireEvent(packet);
//				System.out.println("processPacket= "+packet.toXML());
//			}
//		}, new PacketFilter() {
//			
//			@Override
//			public boolean accept(Packet packet) {
//				// TODO Auto-generated method stub
//				return true;
//			}
//		});
    }

    public void setStatus(boolean available, String status) {
        Presence.Type type = available? Type.available: Type.unavailable;
        Presence presence = new Presence(type);
        presence.setStatus(status);
        connection.sendPacket(presence);
    }
    
    public void destroy() {
        if (connection!=null && connection.isConnected()) {
            connection.disconnect();
        }
    }
    
    
    public int getGroupPosition() {
		return groupPosition;
	}

	public void setGroupPosition(int groupPosition) {
		this.groupPosition = groupPosition;
	}

	public void setChildPosition(int childPositions) {
    	this.childPosition = childPositions;
    }
    
    public int getChildPosition() {
    	return this.childPosition;
    }
    
//    public void setStatusMessage(String status_message) {
//    	this.status_message = status_message;
//    }
//    
//    public String getStatusMessage() {
//    	return this.status_message;
//    }
//    
    public String getOneStatus (String name) {
		Roster roster = connection.getRoster();
		Collection<RosterEntry> entries = roster.getEntries();
		Presence presence;
		String status = "offline1";
		for (RosterEntry rosterEntry : entries) {
			presence = roster.getPresence(rosterEntry.getUser());
			if (rosterEntry.getUser().toString().equalsIgnoreCase(name)) {
//				if (presence.getStatus() != null) {
//	            	System.out.println("koneksi: "+name+"||"+rosterEntry.getName()+" = "+presence.getStatus());
	            	status = presence.getType().name();
//				}
			}
		}
    	return status;
    }
//    
//    public ArrayList<String> getStatus(String groups) {
//    	Roster roster = connection.getRoster();
//        Collection<RosterEntry> entries = roster.getEntries();
//        ArrayList<String> tes = new ArrayList<String>();
////        Presence presence;
//        boolean flag = true;
////        String[] coba = new String[entries.size()];
////        int i = 0;
//		for (RosterEntry e : entries) {
////           if (roster.getPresence(e.getUser()).isAvailable()) {
//        	   Collection<RosterGroup> group = e.getGroups();
//        	   for (RosterGroup g : group) {
//        		   Collection<RosterEntry> en = g.getEntries();
//        		   if (g.getName().equalsIgnoreCase(groups) && flag) {
//        			   for (RosterEntry entry : en) {
////        				   presence = roster.getPresence(entry.getUser());
////        				   System.out.println("^^^^^|pre "+entry.getUser()+": "+presence.getType().name());
////        				   if (roster.getPresence(entry.getUser()).isAvailable()) {
//        					   tes.add(roster.getPresence(entry.getUser()).getType().name());
////        				   }
////            			   coba[i] = entry.getUser();
////            			   i++;
//            		   }
//        			   flag = false;
//        		   }
//        	   }
////           }
//		}
////		System.out.println("***************|GETCONTACTONEGROUP|coba[0]: "+coba[0]+"|...|coba[1]: "+coba[1]+"|...|coba[2]: "+coba[2]+"|***********");
//		return tes;
//    }
    
    public ArrayList<String> getContactUser() {
    	Roster roster = connection.getRoster();
        Collection<RosterEntry> entries = roster.getEntries();
        ArrayList<String> tes = new ArrayList<String>();
		for (RosterEntry e : entries) {
        	   tes.add(e.getUser());
		}
		return tes;
    }
    
    public ArrayList<String> getContact() {
    	Roster roster = connection.getRoster();
        Collection<RosterEntry> entries = roster.getEntries();
        ArrayList<String> tes = new ArrayList<String>();
//        String[] coba = new String[entries.size()];
//        int i = 0;
		for (RosterEntry e : entries) {
           if (roster.getPresence(e.getUser()).isAvailable()) {
        	   tes.add(e.getName());
//        	   coba[i] = e.getUser();
//        	   i++;
           }
		}
//		for (int j=0; j<tes.size(); j++) {
//			System.out.println("########|size: "+tes.size()+"|##|tes: "+tes.get(j)+"|######");
//		}
		return tes;
    }
    
    public ArrayList<String> getContactOneGroup(String groups) {
    	Roster roster = connection.getRoster();
        Collection<RosterEntry> entries = roster.getEntries();
        ArrayList<String> tes = new ArrayList<String>();
        Presence presence;
        boolean flag = true;
//        String[] coba = new String[entries.size()];
//        int i = 0;
		for (RosterEntry e : entries) {
//           if (roster.getPresence(e.getUser()).isAvailable()) {
        	   Collection<RosterGroup> group = e.getGroups();
        	   for (RosterGroup g : group) {
        		   Collection<RosterEntry> en = g.getEntries();
        		   if (g.getName().equalsIgnoreCase(groups) && flag) {
        			   for (RosterEntry entry : en) {
//        				   presence = roster.getPresence(entry.getUser());
//        				   System.out.println("^^^^^|pre "+entry.getUser()+": "+presence.getType().name());
        				   if (roster.getPresence(entry.getUser()).isAvailable()) {
        					   tes.add(entry.getName());
        				   }
//            			   coba[i] = entry.getUser();
//            			   i++;
            		   }
        			   flag = false;
        		   }
        	   }
//           }
		}
//		System.out.println("***************|GETCONTACTONEGROUP|coba[0]: "+coba[0]+"|...|coba[1]: "+coba[1]+"|...|coba[2]: "+coba[2]+"|***********");
		return tes;
    }
    
    public ArrayList<String> getContactGroup() {
    	Roster roster = connection.getRoster();
        Collection<RosterEntry> entries = roster.getEntries();
        ArrayList<String> tes = new ArrayList<String>();
//        String[] coba = new String[entries.size()];
//        String[][] coba2 = new String[entries.size()][10];
//        int i = 0;
//        int m = 0;
//        int n = 0;
		for (RosterEntry e : entries) {
           if (roster.getPresence(e.getUser()).isAvailable()) {
        	   Collection<RosterGroup> group = e.getGroups();
        	   for (RosterGroup g : group) {
        		   Collection<RosterEntry> en = g.getEntries();
//        		   for (RosterEntry entry : en) {
//        			   coba2[m][n] = entry.getUser();
//        			   n++;
//        		   }
        		   tes.add(g.getName());
//        		   coba[i] = g.getName();
//            	   i++;
//            	   m++;
        	   }
           }
		}
//		System.out.println("***************|coba[0]: "+coba[0]+"|...|coba[1]: "+coba[1]+"|...|coba[2]: "+coba[2]+"|***********8");
//		System.out.println("***************|coba2[0][0]: "+coba2[0][0]+"|...|coba2[0][1]: "+coba2[0][1]+"|...|coba2[0][2]"+coba2[0][2]+"|...|");
//		System.out.println("***************|coba2[1][0]: "+coba2[1][0]+"|...|coba2[1][1]: "+coba2[1][1]+"|...|coba2[1][2]"+coba2[1][2]+"|...|");
//		System.out.println("***************|coba2[2][0]: "+coba2[2][0]+"|...|coba2[2][1]: "+coba2[2][1]+"|...|coba2[2][2]"+coba2[2][2]+"|...|");
		return tes;
    }
    
    public ArrayList<String> getAllGroup() {
    	Roster roster = connection.getRoster();
        Collection<RosterEntry> entries = roster.getEntries();
        ArrayList<String> tes = new ArrayList<String>();
        
		for (RosterEntry e : entries) {
    	   Collection<RosterGroup> group = e.getGroups();
    	   for (RosterGroup g : group) {
    		   Collection<RosterEntry> en = g.getEntries();
    		   tes.add(g.getName());
    	   }
		}
		return tes;
    }
    
//    public void contact(ArrayList<String> contacts) {
//    	Roster roster = connection.getRoster();
//        Collection<RosterEntry> entries = roster.getEntries();
//		for (RosterEntry e : entries) {
//           if (roster.getPresence(e.getUser()).isAvailable()) {
//              Log.d("ADD", "NAME_KEY=" + e.getName() + " USERJID_KEY=" + e.getUser());
//              String contact = e.getName();
//              contacts.add(contact);
//           }
//        }
//    }
    
    public void removeUser(String name) {
    	Roster roster = connection.getRoster();
        Collection<RosterEntry> entries = roster.getEntries();
		for (RosterEntry e : entries) {
			if (roster.getPresence(e.getUser()).isAvailable()) {
				if (e.getUser().toString().equalsIgnoreCase(name)) {
					try {
						roster.removeEntry(e);
					} catch (XMPPException e1) {
						e1.printStackTrace();
					}
				}
			}
        }
    }
    
    public void addUser(String user, String name) {
    	Roster roster = connection.getRoster();
        Collection<RosterEntry> entries = roster.getEntries();
		for (RosterEntry e : entries) {
			if (roster.getPresence(e.getUser()).isAvailable()) {
				System.out.println("...............|e.getUser: "+e.getUser()+"|...|name: "+name+"|.........");
				try {
					roster.createEntry(user, name, new String[] {});
				} catch (XMPPException e1) {
					e1.printStackTrace();
				}
			}
        }
    }
    
    
    public boolean isConnected() {
    	if (Koneksi.getInstance().getConnection() == null) {
    		return true;
    	}
    	else {
    		return false;
    	}
    }
    
    public void sendMessage(String to, final String text) {
//    	Roster roster = connection.getRoster();
//    	ArrayList<String> contacts = getContactUser();
//    	for (int i=0; i<contacts.size(); i++) {
//			if (roster.getEntry(contacts.get(i)).getName().equalsIgnoreCase(to)) {
//				to = contacts.get(i);
//			}
//    	}
    	
    	ChatManager chatmanager = connection.getChatManager();
    	Chat newChat = chatmanager.createChat(to+"@"+connection.getServiceName(), new MessageListener() {
			@Override
			public void processMessage(Chat chat, Message message) {
				
			}
		});
    	
    	try {
			newChat.sendMessage(text);
		} catch (XMPPException e) {
			e.printStackTrace();
		}
    }
    
//    public void receiveMessage() {
//    	PacketFilter filter = new MessageTypeFilter(Message.Type.chat);
//	    connection.addPacketListener(new PacketListener() {
//	        public void processPacket(Packet packet) {
//	            Message message = (Message) packet;
//	            if (message.getBody() != null) {
////	                String fromName = StringUtils.parseName(message.getFrom());
////	                System.out.println(fromName + ": " + message.getBody());
//	                mess.add(StringUtils.parseName(message.getFrom()) + ": " + message.getBody());
//	                from.add(StringUtils.parseName(message.getFrom()));
//
//	            }
//	        }
//	    }, filter);
//    }
    
//    public void chattingManager() {
//    	ChatManager chatManager = connection.getChatManager();
//    	chatManager.addChatListener(new ChatManagerListener() {
//			@Override
//			public void chatCreated(Chat chat, boolean createdLocally) {
//				// TODO Auto-generated method stub
////				if (!createdLocally) {
//					chat.addMessageListener(new MessageListener() {
//						@Override
//						public void processMessage(Chat arg0, Message arg1) {
//							// TODO Auto-generated method stub
//							if (arg1.getBody() != null) {
//								from.add(StringUtils.parseName(arg1.getFrom()));
//								to.add(StringUtils.parseName(arg1.getTo()));
//								mess.add(StringUtils.parseName(arg1.getFrom())+": "+arg1.getBody());
//								System.out.println("body= "+arg1.getBody()+"||from= "+arg1.getFrom());
//							}
//							System.out.println(mess);
//							System.out.println(from);
//							System.out.println(to);
//						}
//					});
////				}
//			}
//		});
////    	System.out.println("%%%%%%%%|"+chatting.toArray().length);
//    }
    
    public void precenseSubscription() {
    	
    	final Roster roster = Koneksi.getInstance().getConnection().getRoster();
    	roster.setSubscriptionMode(SubscriptionMode.manual);
    	PacketListener presenceListener = new PacketListener() {
			@Override
			public void processPacket(Packet packet) {
				// TODO Auto-generated method stub
				System.out.println("subscribe listener");
                System.out.println("dua");
                System.out.println(packet.toXML().toString());
                
                if (packet instanceof Message) {
                	System.out.println("Message!!!");
                	System.out.println(((Message) packet).getType());
                	System.out.println(Message.Type.chat);
					if (((Message) packet).getType() == Message.Type.chat) {
						Message mes = (Message)packet;
						// TODO Auto-generated method stub
						if (mes.getBody() != null) {
							from.add(StringUtils.parseName(mes.getFrom()));
							to.add(StringUtils.parseName(mes.getTo()));
							mess.add(StringUtils.parseName(mes.getFrom())+": "+mes.getBody());
							System.out.println("body= "+mes.getBody()+"||from= "+mes.getFrom());
						}
						System.out.println(mess);
						System.out.println(from);
						System.out.println(to);
					}
				}
                else if(packet instanceof Presence) {
					System.out.println(((Presence) packet).getType());
                    if(((Presence)packet).getType().equals(Presence.Type.subscribe)) {
                    	requestfrom = ((Presence)packet).getFrom();
                    	System.out.println("subscribe true");
                    	((Presence)packet).setFrom(((Presence)packet).getTo());
                    	((Presence)packet).setTo(requestfrom);
                    	((Presence)packet).setType(Presence.Type.subscribed);
                    	System.out.println("true1 "+((Presence)packet).toXML());
                        connection.sendPacket(((Presence)packet));
                        ((Presence)packet).setStatus("Online");
                        System.out.println("true2 "+((Presence)packet).toXML());
                        connection.sendPacket(((Presence)packet));
                        ((Presence)packet).setType(Presence.Type.subscribe);
                        System.out.println("true2 "+((Presence)packet).toXML());
                        connection.sendPacket(((Presence)packet));
                        
                        try {
							roster.createEntry(requestfrom, StringUtils.parseName(requestfrom), new String[] {"Friends"});
						} catch (XMPPException e) {
							e.printStackTrace();
						}
                        
                    	System.out.println("2 "+((Presence)packet).getFrom()+"||||||||"+((Presence)packet).getTo());
                    	System.out.println(roster.getEntries());
                    	System.out.println("3 "+StringUtils.parseName(((Presence)packet).getFrom()));
                    	
                    }
//                    System.out.println("4 "+StringUtils.parseName(((Presence)packet).getFrom()));
//                    System.out.println("5 "+StringUtils.parseName(requestfrom));
//                    
//                    if (((Presence) packet).getStatus().equalsIgnoreCase("Online") && 
//                    		StringUtils.parseName(((Presence)packet).getFrom()).equalsIgnoreCase(StringUtils.parseName(requestfrom))) {
//                    	System.out.println("if online");
//                    	System.out.println("6 "+StringUtils.parseResource(((Presence)packet).getFrom()));
//                    	System.out.println("7 "+StringUtils.parseName(((Presence)packet).getFrom()));
//                    	System.out.println("8 "+StringUtils.parseServer(((Presence)packet).getFrom()));
//                    	System.out.println("9 "+StringUtils.parseBareAddress(((Presence)packet).getFrom()));
//                    	System.out.println("0 "+roster.getEntry(((Presence)packet).getFrom()));
//                    	System.out.println("11 "+connection.getUser());
//                    	System.out.println("12 "+StringUtils.parseBareAddress(connection.getUser()));
//
//                		roster.getEntry(StringUtils.parseBareAddress(((Presence)packet).getFrom())).setName(StringUtils.parseName(((Presence)packet).getFrom()));
//                		try {
//    						roster.getGroup("Friends").addEntry(roster.getEntry(StringUtils.parseBareAddress(((Presence)packet).getFrom())));
//    					} catch (XMPPException e) {
//    						e.printStackTrace();
//    					}
//                    }
                }
                
			}
		};
		
		connection.addPacketListener(presenceListener, 
				new OrFilter(new PacketTypeFilter(Presence.class), new PacketTypeFilter(Message.class)));
    }
    
    
//    public void MultiUserChatListener() {
//    	
//    	MultiUserChat.addInvitationListener(connection, new InvitationListener() {
//			@Override
//			public void invitationReceived(XMPPConnection conn, final String room, 
//					final String inviter, String reason, final String password, Message message) {
//				// TODO Auto-generated method stub
//				System.out.println("conn= "+conn+" ||room= "+room+" ||inviter= "+inviter+" || reason= "+reason+" ||password= "+password+" ||message= "+message);
//				
//				System.out.println("*****runn********");
//				
//				MultiUserChat mMultiUserChat = new MultiUserChat(connection, room);
//				try {
//					if (password != null) {
//						mMultiUserChat
//							.join(StringUtils.parseName(Koneksi.getInstance().getConnection().getUser()),
//									password);
//					} else {
//						mMultiUserChat
//							.join(StringUtils.parseName(Koneksi.getInstance().getConnection().getUser()));
//					}
//				} catch (XMPPException e) {
//				}
//				
////				UIThreadUtilities.runOnUIThread(mWaitingForInviteDialog,
////				new Runnable() {
////					public void run() {
//						
////						AlertDialog.Builder adb = new AlertDialog.Builder(context);
////						adb.setTitle("Invitation Received")
////						.setMessage("From: " + inviter)
////						.setPositiveButton("Accept", new DialogInterface.OnClickListener() {
////							public void onClick(DialogInterface dialog, int whichButton) {
////								MultiUserChat mMultiUserChat = new MultiUserChat(connection, room);
////								try {
////									if (password != null) {
////										mMultiUserChat
////											.join(StringUtils.parseName(Koneksi.getInstance().getConnection().getUser()),
////													password);
////									} else {
////										mMultiUserChat
////											.join(StringUtils.parseName(Koneksi.getInstance().getConnection().getUser()));
////									}
//////													registerMUCListeners();
////									// dismissInvitationDialog();
////
////								} catch (XMPPException e) {
////								}
////								/* User clicked Yes so do some stuff */
////							}
////						})
////						.setNegativeButton("Decline",
////							new DialogInterface.OnClickListener() {
////								public void onClick(DialogInterface dialog, int whichButton) {
////									/* User clicked No so do some stuff */
////								}
////						});
////						
////						AlertDialog ad = adb.create();
////						ad.setTitle("Title");
////						ad.show();
//			}
//		});
//
//    }
    
    
    public void configure(ProviderManager pm) {
    	 
        //  Private Data Storage
        pm.addIQProvider("query","jabber:iq:private", new PrivateDataManager.PrivateDataIQProvider());
 
 
        //  Time
        try {
            pm.addIQProvider("query","jabber:iq:time", Class.forName("org.jivesoftware.smackx.packet.Time"));
        } catch (ClassNotFoundException e) {
            Log.w("TestClient", "Can't load class for org.jivesoftware.smackx.packet.Time");
        }
 
        //  Roster Exchange
        pm.addExtensionProvider("x","jabber:x:roster", new RosterExchangeProvider());
 
        //  Message Events
        pm.addExtensionProvider("x","jabber:x:event", new MessageEventProvider());
 
        //  Chat State
        pm.addExtensionProvider("active","http://jabber.org/protocol/chatstates", new ChatStateExtension.Provider());
 
        pm.addExtensionProvider("composing","http://jabber.org/protocol/chatstates", new ChatStateExtension.Provider());
 
        pm.addExtensionProvider("paused","http://jabber.org/protocol/chatstates", new ChatStateExtension.Provider());
 
        pm.addExtensionProvider("inactive","http://jabber.org/protocol/chatstates", new ChatStateExtension.Provider());
 
        pm.addExtensionProvider("gone","http://jabber.org/protocol/chatstates", new ChatStateExtension.Provider());
 
        //  XHTML
        pm.addExtensionProvider("html","http://jabber.org/protocol/xhtml-im", new XHTMLExtensionProvider());
 
        //  Group Chat Invitations
        pm.addExtensionProvider("x","jabber:x:conference", new GroupChatInvitation.Provider());
 
        //  Service Discovery # Items    
        pm.addIQProvider("query","http://jabber.org/protocol/disco#items", new DiscoverItemsProvider());
 
        //  Service Discovery # Info
        pm.addIQProvider("query","http://jabber.org/protocol/disco#info", new DiscoverInfoProvider());
 
        //  Data Forms
        pm.addExtensionProvider("x","jabber:x:data", new DataFormProvider());
 
        //  MUC User
        pm.addExtensionProvider("x","http://jabber.org/protocol/muc#user", new MUCUserProvider());
 
        //  MUC Admin    
        pm.addIQProvider("query","http://jabber.org/protocol/muc#admin", new MUCAdminProvider());
 
 
        //  MUC Owner    
        pm.addIQProvider("query","http://jabber.org/protocol/muc#owner", new MUCOwnerProvider());
 
        //  Delayed Delivery
        pm.addExtensionProvider("x","jabber:x:delay", new DelayInformationProvider());
 
        //  Version
        try {
            pm.addIQProvider("query","jabber:iq:version", Class.forName("org.jivesoftware.smackx.packet.Version"));
        } catch (ClassNotFoundException e) {
            //  Not sure what's happening here.
        }
 
        //  VCard
        pm.addIQProvider("vCard","vcard-temp", new VCardProvider());
 
        //  Offline Message Requests
        pm.addIQProvider("offline","http://jabber.org/protocol/offline", new OfflineMessageRequest.Provider());
 
        //  Offline Message Indicator
        pm.addExtensionProvider("offline","http://jabber.org/protocol/offline", new OfflineMessageInfo.Provider());
 
        //  Last Activity
        pm.addIQProvider("query","jabber:iq:last", new LastActivity.Provider());
 
        //  User Search
        pm.addIQProvider("query","jabber:iq:search", new UserSearch.Provider());
 
        //  SharedGroupsInfo
        pm.addIQProvider("sharedgroup","http://www.jivesoftware.org/protocol/sharedgroup", new SharedGroupsInfo.Provider());
 
        //  JEP-33: Extended Stanza Addressing
        pm.addExtensionProvider("addresses","http://jabber.org/protocol/address", new MultipleAddressesProvider());
 
        //   FileTransfer
        pm.addIQProvider("si","http://jabber.org/protocol/si", new StreamInitiationProvider());
 
//        pm.addIQProvider("query","http://jabber.org/protocol/bytestreams", new BytestreamsProvider());
// 
//        pm.addIQProvider("open","http://jabber.org/protocol/ibb", new IBBProviders.Open());
// 
//        pm.addIQProvider("close","http://jabber.org/protocol/ibb", new IBBProviders.Close());
// 
//        pm.addExtensionProvider("data","http://jabber.org/protocol/ibb", new IBBProviders.Data());
 
        //  Privacy
        pm.addIQProvider("query","jabber:iq:privacy", new PrivacyProvider());
 
//        pm.addIQProvider("command", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider());
//        pm.addExtensionProvider("malformed-action", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.MalformedActionError());
//        pm.addExtensionProvider("bad-locale", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.BadLocaleError());
//        pm.addExtensionProvider("bad-payload", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.BadPayloadError());
//        pm.addExtensionProvider("bad-sessionid", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.BadSessionIDError());
//        pm.addExtensionProvider("session-expired", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.SessionExpiredError());
    }
    

	public static void setFrom(ArrayList<String> from) {
		Koneksi.from = from;
	}

	public static ArrayList<String> getFrom() {
		return from;
	}

	public static void setTo(ArrayList<String> to) {
		Koneksi.to = to;
	}

	public static ArrayList<String> getTo() {
		return to;
	}

	public static void setMess(ArrayList<String> mess) {
		Koneksi.mess = mess;
	}

	public static ArrayList<String> getMess() {
		return mess;
	}

	public static void setStatus_message(String status_message) {
		Koneksi.status_message = status_message;
	}

	public static String getStatus_message() {
		return status_message;
	}

	public String getUserChat() {
		return userChat;
	}

	public void setUserChat(String userChat) {
		this.userChat = userChat;
	}
    
}    